//
//  Release_Service.m
//  HappyStore
//
//  Created by 点点充 on 16/1/23.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "Release_Service.h"

@interface Release_Service ()<UICollectionViewDataSource,UICollectionViewDelegate,UITextFieldDelegate>
{
    UICollectionView *mainCollection;
    
    UIButton *btnAddHeader;
    UIButton *btnDeleHeader;
    NSString *fullPathHeader;//头像地址
    
    UITextField *tfTitle;
    UITextField *tfPrice;
    
    //地区
    UILabel *labAddress;
    NSString *provinceStr;
    NSString *cityStr;
    NSString *districtStr;
    
    
    //类型
    UILabel *labType;
    
    //标签
    UIButton *btnTagert1;
    UIButton *btnTagert2;
    UIButton *btnTagert3;
    
    UITextView *tvDetail;
    
    
    //发布按钮
    UIButton *btnRelease;
    
    NSMutableArray *muArySaveImg;//保存5张图片
    
    
    BOOL isSelectedHeader;
    
    
    
    
    SingleSelectedDialog *tableViewIndustry;
    
    SelectedAddress *selectAddress;//选择地区
    
    
    
    NSArray *aryTypeData;//服务类型数据
    
    NSString *strID;
    
}
@end

@implementation Release_Service

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
    }else{
        [SVProgressHUD showErrorWithStatus:@"请先登录!"];
        [SVProgressHUD dismissafterDelay:kHideHudDelay];
        
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    //找出导航栏的下边的黑线
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = NO;
    navBarHairlineImageView.alpha = 0.5f;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    //找出导航栏的下边的黑线
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"发布企业服务";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    // 设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    
    muArySaveImg = [NSMutableArray arrayWithObject:[UIImage imageNamed:@"re_project_add2"]];
    
    isSelectedHeader = YES;
    
    
    aryTypeData = @[@"软件开发",@"融资担保",@"法律咨询",@"财务会计",@"商标专利",@"展会会务",@"广告传媒",@"工商注册",@"营销策划"];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
}

-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            return 150;
            break;
        case 1:
            return 350;
            break;
        default:
            return 80;
            break;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cell1 = @"cell1";
    static NSString *cell2 = @"cell2";
    
    UITableViewCell *cell;
    
    switch (indexPath.row) {
        case 0://头像＋3行
        {
            cell = [tableView dequeueReusableCellWithIdentifier:cell1 forIndexPath:indexPath];
            
//            btnAddHeader = [cell viewWithTag:10];
//            btnAddHeader.layer.masksToBounds = YES;
//            btnAddHeader.layer.cornerRadius = 5.f;
//            [btnAddHeader addTarget:self action:@selector(btnClickAddHeader) forControlEvents:UIControlEventTouchUpInside];
//            btnDeleHeader = [cell viewWithTag:11];
//            if ([btnAddHeader.currentImage isEqual:[UIImage imageNamed:@"re_project_add1"]]) {
//                btnDeleHeader.hidden = YES;
//            }else {
//                btnDeleHeader.hidden = NO;
//            }
//            
//            [btnDeleHeader addTarget:self action:@selector(btnClickDeleHeader) forControlEvents:UIControlEventTouchUpInside];
            
            tfTitle = [cell viewWithTag:12];
            
            
            if (labType == nil) {
                for (int i = 0; i<3; i++) {
                    
                    switch (i) {
                        case 0://服务类型
                        {
                            labType = [[UILabel alloc] initWithFrame:(CGRect){25,70+50*i,280,30}];
                            labType.text = @"服务分类";
                            labType.font = [UIFont systemFontOfSize:12.5f];
                            labType.textColor = [UIColor colorWithWhite:0.75 alpha:1.f];
                            
                            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                            [btn setImage:[UIImage imageNamed:@"re_project_right"] forState:UIControlStateNormal];
                            btn.frame = (CGRect){20,70+50*i,280,30};
                            btn.layer.borderColor = [UIColor colorWithRed:201/255.0f green:202/255.0f blue:202/255.0f alpha:1.0f].CGColor;
                            btn.layer.borderWidth = 0.5f;
                            btn.layer.masksToBounds = YES;
                            btn.layer.cornerRadius = 5.0f;
                            
                            btn.imageEdgeInsets = UIEdgeInsetsMake(0, 280-40+1.5, 0, 0);
                            [btn addTarget:self action:@selector(btnClickType:) forControlEvents:UIControlEventTouchUpInside];
                            
                            [cell addSubview:labType];
                            [cell addSubview:btn];
                        }
                            break;
                        case 1://地区
                        {
                            labAddress = [[UILabel alloc] initWithFrame:(CGRect){25,70+50*i,280,30}];
                            labAddress.font = [UIFont systemFontOfSize:12.5f];
                            labAddress.textColor = [UIColor colorWithWhite:0.75 alpha:1.f];
                            labAddress.text = @"服务区域";
                            
                            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                            [btn setImage:[UIImage imageNamed:@"re_project_right"] forState:UIControlStateNormal];
                            btn.frame = (CGRect){20,70+50*i,280,30};
                            btn.layer.borderColor = [UIColor colorWithRed:201/255.0f green:202/255.0f blue:202/255.0f alpha:1.0f].CGColor;
                            btn.layer.borderWidth = 0.5f;
                            btn.layer.masksToBounds = YES;
                            btn.layer.cornerRadius = 5.0f;
                            
                            btn.imageEdgeInsets = UIEdgeInsetsMake(0, 280-40+1.5, 0, 0);
                            [btn addTarget:self action:@selector(btnClickAddress) forControlEvents:UIControlEventTouchUpInside];
                            
                            [cell addSubview:labAddress];
                            [cell addSubview:btn];
                        }
                            break;
                    }
                    
                }
            }
            
        }
            break;
        case 1://价格＋文本输入框+发布
        {
            cell = [tableView dequeueReusableCellWithIdentifier:cell2 forIndexPath:indexPath];
            tfPrice = [cell viewWithTag:13];
            tfPrice.delegate = self;
            UIButton *button = [cell viewWithTag:20];
            button.layer.borderColor = [UIColor colorWithRed:201/255.0f green:202/255.0f blue:202/255.0f alpha:1.0f].CGColor;
            button.layer.borderWidth = 0.5f;
            button.layer.masksToBounds = YES;
            button.layer.cornerRadius = 5.0f;
            tvDetail = [cell viewWithTag:10];
            tvDetail.layer.masksToBounds = YES;
            tvDetail.layer.cornerRadius = 5.f;
            tvDetail.delegate = self;
            tvDetail.layer.borderColor = [UIColor colorWithRed:201/255.0f green:202/255.0f blue:202/255.0f alpha:1.0f].CGColor;
            tvDetail.layer.borderWidth = 0.5f;
            tvDetail.font = [UIFont systemFontOfSize:12.5f];
            tvDetail.textColor = [UIColor colorWithWhite:0.75 alpha:1.f];
            if (tvDetail.text.length == 0) {
                tvDetail.text = @"请输入服务描述和注意事项";
            }
//            
//            mainCollection = [cell viewWithTag:11];
//            mainCollection.delegate = self;
//            mainCollection.dataSource = self;
//            
//            btnTagert1 = [cell viewWithTag:12];
//            btnTagert2 = [cell viewWithTag:13];
//            btnTagert3 = [cell viewWithTag:14];
//            [btnTagert1 addTarget:self action:@selector(btnClickTagert:) forControlEvents:UIControlEventTouchUpInside];
//            [btnTagert2 addTarget:self action:@selector(btnClickTagert:) forControlEvents:UIControlEventTouchUpInside];
//            [btnTagert3 addTarget:self action:@selector(btnClickTagert:) forControlEvents:UIControlEventTouchUpInside];
//            
//            btnTagert1.layer.masksToBounds = YES;
//            btnTagert1.layer.cornerRadius = 5.f;
//            btnTagert2.layer.masksToBounds = YES;
//            btnTagert2.layer.cornerRadius = 5.f;
//            btnTagert3.layer.masksToBounds = YES;
//            btnTagert3.layer.cornerRadius = 5.f;
            
            
            btnRelease = [cell viewWithTag:15];
            btnRelease.layer.masksToBounds = YES;
            btnRelease.layer.cornerRadius= 5.f;
            [btnRelease addTarget:self action:@selector(btnClickRelease:) forControlEvents:UIControlEventTouchUpInside];
            
            
        }
            break;
    }
    
    
    
    return cell;
    
}

#pragma mark - 选择头像
- (void)btnClickAddHeader
{
    isSelectedHeader = YES;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"照片选择"
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"相机",@"相册", nil];
    actionSheet.tag = 333;
    [actionSheet showInView:self.view];
}

#pragma mark - 删除头像
- (void)btnClickDeleHeader
{
    [btnAddHeader setImage:[UIImage imageNamed:@"re_project_add1"] forState:UIControlStateNormal];
    btnDeleHeader.hidden = YES;
}


#pragma mark - 选择服务类型
- (void)btnClickType:(UIButton *)sender
{
    tableViewIndustry = [SingleSelectedDialog sharedSelectedAddress];
    tableViewIndustry.delegatee = self;
    [tableViewIndustry btnClickAddressWithData:aryTypeData];
}

- (void)seceltedRow:(NSInteger)rrow
{
    labType.text = aryTypeData[rrow];
    labType.textColor = [UIColor colorWithRed:137/255.0f green:137/255.0f blue:137/255.0f alpha:1.0f];
}


#pragma mark - 选择地区
- (void)btnClickAddress
{
    selectAddress = [SelectedAddress sharedSelectedAddress];
    selectAddress.delegatee = self;
    [selectAddress btnClickAddress];
}

- (void)seceltedRowSshowMsg:(NSString *)showMsg andProvince:(NSString *)strProvince andCity:(NSString *)strCity andDistrict:(NSString *)strDistrict
{
    labAddress.text = showMsg;
    labAddress.textColor = [UIColor colorWithRed:137/255.0f green:137/255.0f blue:137/255.0f alpha:1.0f];
    provinceStr = strProvince;
    cityStr = strCity;
    districtStr = strDistrict;
}



#pragma mark - 选择标签
- (void)btnClickTagert:(UIButton *)sender
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"添加标签" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *nameField = [alert textFieldAtIndex:0];
    nameField.placeholder = @"最多输入4个字";
    
    [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
        if(buttonIndex == 1){
            UITextField *tf=[alert textFieldAtIndex:0];
            if (tf.text.length > 0 && tf.text.length < 5) {
                [sender setTitle:tf.text forState:UIControlStateNormal];
                [sender setImage:nil forState:UIControlStateNormal];
                sender.backgroundColor = [UIColor colorWithRed:32/255.f green:165/255.f blue:240/255.f alpha:1.f];
            }else {

                [self showSingleIconBubble:@"最多输入4个字"];

            }
        }
    }];
    
}





#pragma mark- UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return muArySaveImg.count;
    
}
//行内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cell1 = @"cell1";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cell1 forIndexPath:indexPath];
    
    //    NSLog(@"子视图:%@",cell.subviews);
    
    UIButton *btnImage = [cell viewWithTag:10];
    btnImage.layer.masksToBounds = YES;
    btnImage.layer.cornerRadius = 5.f;
    [btnImage setImage:muArySaveImg[indexPath.row] forState:UIControlStateNormal];
    [btnImage addTarget:self action:@selector(btnClickAddImage:) forControlEvents:UIControlEventTouchUpInside];
    btnImage.hidden = NO;
    btnImage.userInteractionEnabled = YES;
    
    UIButton *btnDelete = [cell viewWithTag:11];
    btnDelete.hidden = NO;
    [btnDelete addTarget:self action:@selector(btnClickDeleteImage:) forControlEvents:UIControlEventTouchUpInside];
    
    //    NSLog(@"子视图:%@",btnDelete.superview);
    
    if (muArySaveImg.count == 1 || indexPath.row == muArySaveImg.count-1) {
        btnDelete.hidden = YES;
    }else {
        btnImage.userInteractionEnabled = NO;
    }
    
    if (muArySaveImg.count == 6 && indexPath.row == muArySaveImg.count -1) {
        btnImage.hidden = YES;
        btnDelete.hidden = YES;
    }
    
    
    
    return cell;
}

#pragma mark - 添加5张图片
- (void)btnClickAddImage:(UIButton *)sender
{
    isSelectedHeader = NO;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"照片选择"
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"相机",@"相册", nil];
    actionSheet.tag = 333;
    [actionSheet showInView:self.view];
}

#pragma mark - 选择照片
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (actionSheet.tag) {
        case 222:
        {
            
        }
            break;
        case 333:
        {
            //先设定sourceType为相机，然后判断相机是否可用（ipod）没相机，不可用将sourceType设定为相片库
            UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
            pickerImage.delegate = self;
            pickerImage.allowsEditing = YES;//设置可编辑
            switch (buttonIndex) {
                case 0:
                {
                    //NSLog(@"相机");
                    pickerImage.sourceType = UIImagePickerControllerSourceTypeCamera;
                    [self presentViewController:pickerImage animated:YES completion:nil];//进入照相界面
                }
                    break;
                case 1:
                {
                    //NSLog(@"相册");
                    pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库
                    [self presentViewController:pickerImage animated:YES completion:nil];//进入照相界面
                }
                    break;
                case 2:
                {
                    //NSLog(@"取消");
                }
                    break;
            }
        }
            break;
    }
    
}

//点击相册中的图片 货照相机照完后点击use  后触发的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^{}];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    if (isSelectedHeader) {//选择的头像
        [btnAddHeader setImage:image forState:UIControlStateNormal];
        btnDeleHeader.hidden = NO;
    }else {
        //5张详情 图片
        [muArySaveImg insertObject:image atIndex:0];
        if (muArySaveImg.count == 2) {
            [muArySaveImg replaceObjectAtIndex:1 withObject:[UIImage imageNamed:@"re_project_add3"]];
        }
        
        if (muArySaveImg.count == 4) {
            [_mainTableView reloadData];
        }
        
        [mainCollection reloadData];
    }
    
}

//点击cancel 调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^{}];
}

#pragma mark - 保存图片至沙盒
- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.1);
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}

#pragma mark - 删除5张图片
- (void)btnClickDeleteImage:(UIButton *)sender
{
    UIView *viewContent = sender.superview;
    
    NSIndexPath *indexPath = [mainCollection indexPathForCell:(UICollectionViewCell *)viewContent.superview];
    //NSLog(@"--------%ld",indexPath.row);
    [muArySaveImg removeObjectAtIndex:indexPath.row];
    
    [mainCollection reloadData];
    
    if (muArySaveImg.count == 3) {
        [_mainTableView reloadData];
    }
    
    
    
    
}


#pragma mark 照片的时间名称
- (NSString*)dateString
{
    NSMutableString*string=[[NSMutableString alloc] init];
    NSDate*dayDate=[NSDate date];
    NSDateFormatter*dayFormatter=[[NSDateFormatter alloc] init];
    [dayFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateStrings= [dayFormatter stringFromDate:dayDate];
    NSArray*dayArray=[dateStrings componentsSeparatedByString:@"-"];
    for (int i=0; i<[dayArray count]; i++) {
        [string appendFormat:@"%@",[dayArray objectAtIndex:i]];
    }
    NSDate*timeDate=[NSDate date];
    NSDateFormatter*timeFormatter=[[NSDateFormatter alloc] init];
    [timeFormatter setDateFormat:@"HH:mm:ss:SSS"];
    NSString *timeString= [timeFormatter stringFromDate:timeDate];
    NSArray*timeArray=[timeString componentsSeparatedByString:@":"];
    for (int i=0; i<[timeArray count]; i++) {
        [string appendFormat:@"%@",[timeArray objectAtIndex:i]];
    }
    return string;
    
}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ([textView.text isEqualToString:@"请输入服务描述和注意事项"]) {
        textView.text = @"";
        textView.textColor = [UIColor colorWithRed:137/255.0f green:137/255.0f blue:137/255.0f alpha:1.0f];
    }
    
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if (textView.text.length == 0) {
        textView.text = @"请输入服务描述和注意事项";
        textView.textColor = [UIColor colorWithWhite:0.75 alpha:1.f];
    }
    
}


#pragma mark - 发布
- (void)btnClickRelease:(UIButton *)btn
{
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
    BOOL isOK = YES;

    
    if (isOK && tfTitle.text.length == 0) {
        isOK = NO;

        [self showSingleIconBubble:@"请输入标题"];

    }

    
    if (isOK && [labType.text isEqualToString:@"服务分类"]) {
        isOK = NO;
        [self showSingleIconBubble:@"请选择服务类型"];

    }
    
    
    
    if (isOK && [labAddress.text isEqualToString:@"服务区域"]) {
        isOK = NO;
        [self showSingleIconBubble:@"请选择地区"];

    }
    
    
    if (isOK) {
        if ([tvDetail.text isEqualToString:@"请输入服务描述和注意事项"] || tvDetail.text.length == 0) {
            isOK = NO;
           [self showSingleIconBubble:@"请输入详细描述"];

        }
    }
    
    NSMutableString *strTagert = [NSMutableString string];
    if (btnTagert1.currentTitle.length != 0) {
        [strTagert appendString:btnTagert1.currentTitle];
        [strTagert appendString:@","];
    }
    if (btnTagert2.currentTitle.length != 0) {
        [strTagert appendString:btnTagert2.currentTitle];
        [strTagert appendString:@","];
    }
    if (btnTagert3.currentTitle.length != 0) {
        [strTagert appendString:btnTagert3.currentTitle];
        [strTagert appendString:@","];
    }
    
    if (strTagert.length != 0) {
        [strTagert deleteCharactersInRange:NSMakeRange(strTagert.length-1, 1)];
    }
    
    if (isOK) {
        //暂停用户交互
        btn.userInteractionEnabled = NO;
        //categoryName=资金性质（软件开发.融资担保.法律咨询.财务会计.商标专利.展会会务.广告传媒.工商注册.营销策划）
        [self showRoundProgressWithTitle:@"请稍后..."];
        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"usertype"] forKey:@"useType"];//用户类型
        [muDicParameters setObject:tfTitle.text forKey:@"title"];
        [muDicParameters setObject:labType.text forKey:@"categoryName"];
        [muDicParameters setObject:tfPrice.text forKey:@"money"];
        [muDicParameters setObject:provinceStr forKey:@"provinceName"];//省市
        [muDicParameters setObject:cityStr forKey:@"cityName"];
        [muDicParameters setObject:districtStr forKey:@"areaName"];
        [muDicParameters setObject:tvDetail.text forKey:@"description"];
        if (strTagert.length != 0) {
            
            [muDicParameters setObject:strTagert forKey:@"lable"];
        
        }
        
        [LSHttpTool sendHttpData:@"addService_app_service.im.lensum" params:muDicParameters success:^(id responseObject) {
            btn.userInteractionEnabled = YES;
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                        //NSLog(@"%@",dicInfo);

            if ([dicInfo[@"result"] integerValue] == 1) {
                [self hideBubble];
                strID = dicInfo[@"data"];
                //iOS8.0+
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                                               message:@"为了保证平台的质量，您的服务会在我们审核通过后展示！"
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                                      handler:^(UIAlertAction * action) {
                                                                          [self.navigationController popViewControllerAnimated:YES];}];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
                        }else {
                            [self showSingleIconBubble:dicInfo[@"msg"]];
                        }

        } failure:^(NSError *error) {
            btn.userInteractionEnabled = YES;

            [self showSingleIconBubble:error.localizedDescription];

        }];

     
    }
    
    

    }else{
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
    
    
}


- (void)btnDismiss
{
    [self.navigationController popViewControllerAnimated:YES];
    
    NSMutableDictionary *muDic = [NSMutableDictionary dictionary];
    [muDic setObject:strID forKey:@"id"];
    [muDic setObject:@"4" forKey:@"type"];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"gotoPush" object:nil userInfo:muDic];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == tfPrice) {
        if (tfPrice.text.length >16) {

            [self showSingleIconBubble:@"金额不能超过15位"];

            tfPrice.text = @"";
        }
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
